package DatabaseImp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;

import Database.DBConnecter;
import DatabasePO.AccountPO;

public class AccountDBImpl {
	
	Connection connection = null;
	PreparedStatement preparedStatement = null;
	ResultSet resultSet = null;

	DBConnecter dbConnecter = DBConnecter.getInstance();
	
	public AccountPO queryAccount(String acc, String password){
		AccountPO account = null;
		
		connection = dbConnecter.getConnecter();
		String sqlString = " select * from account where acc = ? and passwd = ?";
		
		
		try {
			preparedStatement = connection.prepareStatement(sqlString);
			preparedStatement.setString(1, acc);
			preparedStatement.setString(2, password);
			resultSet=preparedStatement.executeQuery();
			
			
			if(resultSet.next()){
				account=new AccountPO();
				account.setAccount(resultSet.getString("acc"));
				account.setPassword(resultSet.getString("passwd"));
				account.setRank(resultSet.getString("rank"));
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			dbConnecter.closeConnecter(connection);
			dbConnecter.closeResultSet(resultSet);
			dbConnecter.closePrepareStatement(preparedStatement);

		}
	
		
		return account;
	}

}
